package org.cyx.javasx.annotation;

import java.lang.reflect.Field;

import org.cyx.javasx.view.IContainer;

public class AnnotationResolver {

    public static void run(IContainer container) {
        Class clazz = container.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (field.isAnnotationPresent(ComponentGet.class)) {
                ComponentGet componentGet = field.getAnnotation(ComponentGet.class);
                String id = componentGet.id();
                Object obj = container.findViewById(id);
                field.setAccessible(true);
                try {
                    field.set(container, obj);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
           }
       }
    }
}